﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using Tanmia.Basis.Domain;

namespace Tanmia.Domain
{
    public class InvoiceDomain : BaseDomainObject<Invoice>
    {
        private OutputNoteDomain outputNoteObj = new OutputNoteDomain();
        private InputNoteDomain inputNoteObj = new InputNoteDomain();
        private VoucherDomain voucherObj = new VoucherDomain();
        private static AccountDomain accountObj = new AccountDomain();

        /// <summary>
        /// ترحيل الفاتورة
        /// </summary>
        /// <param name="invoice">الفاتورة المراد ترحيلها</param>
        public void Post(Invoice invoice)
        {
            if (invoice.InvoiceID == 0)
                throw new InvalidOperationException("لا يمكن ترحيل فاتورة لم تحفظ بعد");

            if (invoice.InvoiceType == InvoiceTypeEnum.Sale || invoice.InvoiceType == InvoiceTypeEnum.ReturnBuy)
            {
                OutputNote outputNote = ConvertToOutputNote(invoice);
                if (outputNoteObj.SaveOrUpdate(outputNote).OutputNoteID == 0)
                    throw new Exception("حدث خطأ أثناء حفظ أمر الإخراج");
            }
            else
            {
                InputNote inputNote = ConvertToInputNote(invoice);
                if (inputNoteObj.SaveOrUpdate(inputNote).InputNoteID == 0)
                    throw new Exception("حدث خطأ أثناء حفظ أمر الإدخال");
            }

            Voucher voucher = ConvertToVoucher(invoice);
            voucher.InvoiceID = invoice.InvoiceID;

            if (voucherObj.SaveOrUpdate(voucher).VoucherID == 0)
                throw new Exception("حدث خطأ أثناء إنشاء القيد المالي");
        }

        /// <summary>
        /// فك ترحيل الفاتورة
        /// </summary>
        /// <param name="invoice">الفاتورة المراد فك ترحيلها</param>
        public void Unpost(Invoice invoice)
        {
        }

        #region Other things
        #region Convert to Note
        private OutputNote ConvertToOutputNote(Invoice invoice)
        {
            OutputNote reVal = new OutputNote
            {
                CreateDate = invoice.CreateDate,
                Notes = string.Format("أمر اخراج مواد بناء على الفاتورة رقم : {0}.", invoice.InvoiceID),
                Repository = invoice.Repository,
                NoteNumber = invoice.InvoiceID.ToString(),
                User = invoice.User
            };

            foreach (InvoiceDetail detail in invoice.Details)
                reVal.Details.Add(new StockMovement
                {
                    Item = detail.Item,
                    Part = detail.Part,
                    Quantity = detail.Quantity,
                    Note = detail.Note,
                    Sacle = detail.Unit.Scale,
                    UnitName = detail.Unit.Name,
                    UnitPrice = detail.UnitPrice
                });

            return reVal;
        }

        private InputNote ConvertToInputNote(Invoice invoice)
        {
            InputNote reVal = new InputNote
            {
                CreateDate = invoice.CreateDate,
                Notes = string.Format("أمر ادخال مواد بناء على الفاتورة رقم : {0}.", invoice.InvoiceID),
                Repository = invoice.Repository,
                NoteNumber = invoice.InvoiceID.ToString(),
                User = invoice.User
            };

            foreach (InvoiceDetail detail in invoice.Details)
                reVal.Details.Add(new StockMovement
                {
                    Item = detail.Item,
                    Part = detail.Part,
                    Quantity = detail.Quantity,
                    Note = detail.Note,
                    Sacle = detail.Unit.Scale,
                    UnitName = detail.Unit.Name
                });

            return reVal;
        }
        #endregion


        private Voucher ConvertToVoucher(Invoice invoice)
        {
            if (invoice.InvoiceType == InvoiceTypeEnum.Sale & invoice.PaymentMethod == PaymentMethodEnum.Paid)
                return GetPaidSale(invoice);
            if (invoice.InvoiceType == InvoiceTypeEnum.Sale & invoice.PaymentMethod == PaymentMethodEnum.Unpaid)
                return GetUnpaidSale(invoice);

            if (invoice.InvoiceType == InvoiceTypeEnum.Buy & invoice.PaymentMethod == PaymentMethodEnum.Paid)
                return GetPaidBuy(invoice);
            if (invoice.InvoiceType == InvoiceTypeEnum.Buy & invoice.PaymentMethod == PaymentMethodEnum.Unpaid)
                return GetUnpaidBuy(invoice);

            if (invoice.InvoiceType == InvoiceTypeEnum.ReturnSale & invoice.PaymentMethod == PaymentMethodEnum.Paid)
                return GetPaidRSale(invoice);
            if (invoice.InvoiceType == InvoiceTypeEnum.ReturnSale & invoice.PaymentMethod == PaymentMethodEnum.Unpaid)
                return GetUnpaidRSale(invoice);

            if (invoice.InvoiceType == InvoiceTypeEnum.ReturnBuy & invoice.PaymentMethod == PaymentMethodEnum.Paid)
                return GetPaidRBuy(invoice);
            if (invoice.InvoiceType == InvoiceTypeEnum.ReturnBuy & invoice.PaymentMethod == PaymentMethodEnum.Unpaid)
                return GetUnpaidRBuy(invoice);

            return null;
        }
        #region Get Voucher
        #region Get Sale Voucher
        private Voucher GetPaidSale(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TPaidSaleWithoutDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.InvoiceID);  //دائن
                temp.Details[1].Account = invoice.Person.Account;
                temp.Details[1].Credit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //مدين
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Debit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[3].Credit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TPaidSaleWithDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID); //مدين
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.InvoiceID);  //دائن
                temp.Details[1].Account = invoice.Person.Account;
                temp.Details[1].Credit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //مدين
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Debit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[3].Debit = invoice.Discount;

                temp.Details[4].Notes = string.Format(temp.Details[4].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[4].Credit = invoice.Total;

                return temp;
            }
        }

        private Voucher GetUnpaidSale(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TUnpaidSaleWithoutDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[1].Credit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TUnpaidSaleWithDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[1].Debit = invoice.Discount;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[2].Credit = invoice.Total;

                return temp;
            }
        }
        #endregion

        #region Get Buy Voucher
        private Voucher GetPaidBuy(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TPaidBuyWithoutDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID); //دائن
                temp.Details[1].Credit = invoice.Final;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID); //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID); //دائن
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Credit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.Person.Name, invoice.InvoiceID); //مدين
                temp.Details[3].Debit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TPaidBuyWithDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID); //دائن
                temp.Details[1].Credit = invoice.Final;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //دائن
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Credit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[3].Credit = invoice.Discount;

                temp.Details[4].Notes = string.Format(temp.Details[4].Notes, invoice.Person.Name, invoice.InvoiceID); //مدين
                temp.Details[4].Debit = invoice.Total;

                return temp;
            }
        }

        private Voucher GetUnpaidBuy(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TUnpaidBuyWithoutDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //دائن
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Credit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[1].Debit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TUnpaidBuyWithDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //دائن
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Credit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[1].Credit = invoice.Discount;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[2].Debit = invoice.Total;

                return temp;
            }
        }
        #endregion

        #region Get Return Sale Voucher
        private Voucher GetPaidRSale(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TPaidRSaleWithoutDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID); //مدين
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.InvoiceID);  //دائن
                temp.Details[1].Account = invoice.Person.Account;
                temp.Details[1].Credit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //مدين
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Debit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[3].Credit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TPaidRSaleWithDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[0].Debit = invoice.Total;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //دائن
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Credit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.InvoiceID);  //مدين
                temp.Details[3].Account = invoice.Person.Account;
                temp.Details[3].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[1].Credit = invoice.Discount;

                temp.Details[4].Notes = string.Format(temp.Details[4].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[4].Credit = invoice.Final;

                return temp;
            }
        }

        private Voucher GetUnpaidRSale(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TUnpaidBuyWithoutDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.InvoiceID);  //دائن
                temp.Details[1].Account = invoice.Person.Account;
                temp.Details[1].Credit = invoice.Final;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[0].Debit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TUnpaidBuyWithDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //دائن
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Credit = invoice.Final;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID); //مدين
                temp.Details[0].Debit = invoice.Total;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[1].Credit = invoice.Discount;

                return temp;
            }
        }
        #endregion

        #region Get Return Buy Voucher
        private Voucher GetPaidRBuy(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TPaidRBuyWithoutDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.InvoiceID);  //دائن
                temp.Details[1].Account = invoice.Person.Account;
                temp.Details[1].Credit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.InvoiceID);  //مدين
                temp.Details[2].Account = invoice.Person.Account;
                temp.Details[2].Debit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[3].Credit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TPaidRBuyWithDiscount.Clone() as Voucher;

                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[1].Debit = invoice.Discount;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[3].Notes = string.Format(temp.Details[3].Notes, invoice.InvoiceID);  //مدين
                temp.Details[3].Account = invoice.Person.Account;
                temp.Details[3].Debit = invoice.Final;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[2].Credit = invoice.Total;

                temp.Details[4].Notes = string.Format(temp.Details[4].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[4].Credit = invoice.Final;

                return temp;
            }
        }

        private Voucher GetUnpaidRBuy(Invoice invoice)
        {
            if (invoice.Discount == 0)
            {
                Voucher temp = TUnpaidRBuyWithoutDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[1].Credit = invoice.Final;

                return temp;
            }
            else
            {
                Voucher temp = TUnpaidRBuyWithDiscount.Clone() as Voucher;
                temp.CreateDate = DateTime.Now;
                temp.User = invoice.User;

                temp.Details[0].Notes = string.Format(temp.Details[0].Notes, invoice.InvoiceID);  //مدين
                temp.Details[0].Account = invoice.Person.Account;
                temp.Details[0].Debit = invoice.Final;

                temp.Details[1].Notes = string.Format(temp.Details[1].Notes, invoice.Person.Name, invoice.InvoiceID);  //مدين
                temp.Details[1].Debit = invoice.Discount;

                temp.Details[2].Notes = string.Format(temp.Details[2].Notes, invoice.Person.Name, invoice.InvoiceID);  //دائن
                temp.Details[2].Credit = invoice.Total;

                return temp;
            }
        }
        #endregion
        #endregion


        #region private template

        /// <summary>
        /// قالب لفاتورة بيع نقدية وبدون حسم
        /// </summary>
        private static Voucher TPaidSaleWithoutDiscount = new Voucher { Notes = "قيد فاتورة مبيع نقدية بدون حسم" };
        /// <summary>
        /// فاتورة بيع غير نقدية وبدون حسم
        /// </summary>
        private static Voucher TUnpaidSaleWithoutDiscount = new Voucher { Notes = "قيد فاتورة مبيع آجلة بدون حسم" };
        /// <summary>
        /// فاتورة بيع نقدية مع حسم
        /// </summary>
        private static Voucher TPaidSaleWithDiscount = new Voucher { Notes = "قيد فاتورة مبيع نقدية مع حسم" };
        /// <summary>
        /// فاتورة بييع غير نقدية مع حسم
        /// </summary>
        private static Voucher TUnpaidSaleWithDiscount = new Voucher { Notes = "قيد فاتورة مبيع آجلة مع حسم" };

        /// <summary>
        /// قالب لفاتورة شراء نقدية وبدون حسم
        /// </summary>
        private static Voucher TPaidBuyWithoutDiscount = new Voucher { Notes = "قيد فاتورة شراء نقدية بدون حسم" };
        /// <summary>
        /// فاتورة شراء غير نقدية وبدون حسم
        /// </summary>
        private static Voucher TUnpaidBuyWithoutDiscount = new Voucher { Notes = "قيد فاتورة شراء آجلة بدون حسم" };
        /// <summary>
        /// فاتورة شراء نقدية مع حسم
        /// </summary>
        private static Voucher TPaidBuyWithDiscount = new Voucher { Notes = "قيد فاتورة شراء نقدية مع حسم" };
        /// <summary>
        /// فاتورة شراء غير نقدية مع حسم
        /// </summary>
        private static Voucher TUnpaidBuyWithDiscount = new Voucher { Notes = "قيد فاتورة شراء آجلة مع حسم" };

        /// <summary>
        /// قالب لفاتورة مرتجع بيع نقدية وبدون حسم
        /// </summary>
        private static Voucher TPaidRSaleWithoutDiscount = new Voucher { Notes = "قيد فاتورة مرتجع مبيع نقدية بدون حسم" };
        /// <summary>
        /// فاتورة مرتجع بيع غير نقدية وبدون حسم
        /// </summary>
        private static Voucher TUnpaidRSaleWithoutDiscount = new Voucher { Notes = "قيد فاتورة مرتجع مبيع آجلة بدون حسم" };
        /// <summary>
        /// فاتورة مرتجع بيع نقدية مع حسم
        /// </summary>
        private static Voucher TPaidRSaleWithDiscount = new Voucher { Notes = "قيد فاتورة مرتجع مبيع نقدية مع حسم" };
        /// <summary>
        /// فاتورة مرتجع بيع غير نقدية مع حسم
        /// </summary>
        private static Voucher TUnpaidRSaleWithDiscount = new Voucher { Notes = "قيد فاتورة مرتجع مبيع آجلة مع حسم" };

        /// <summary>
        /// قالب لفاتورة مرتجع شراء نقدية وبدون حسم
        /// </summary>
        private static Voucher TPaidRBuyWithoutDiscount = new Voucher { Notes = "قيد فاتورة مرتجع شراء نقدية بدون حسم" };
        /// <summary>
        /// فاتورة مرتجع شراء غير نقدية وبدون حسم
        /// </summary>
        private static Voucher TUnpaidRBuyWithoutDiscount = new Voucher { Notes = "قيد فاتورة مرتجع شراء آجلة بدون حسم" };
        /// <summary>
        /// فاتورة مرتجع شراء نقدية مع حسم
        /// </summary>
        private static Voucher TPaidRBuyWithDiscount = new Voucher { Notes = "قيد فاتورة مرتجع شراء نقدية مع حسم" };
        /// <summary>
        /// فاتورة مرتجع شراء غير نقدية مع حسم
        /// </summary>
        private static Voucher TUnpaidRBuyWithDiscount = new Voucher { Notes = "قيد فاتورة مرتجع شراء آجلة مع حسم" };

        #endregion
        static InvoiceDomain()
        {
            #region فواتير البيع بكافة أحوالها
            //فاتورة بيع نقدية بدون حسم
            TPaidSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة مبيع نقدية لـ {0}, رقم: {1}." });
            TPaidSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مبيع نقدية رقم: {0}." });
            TPaidSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مبيع نقدية رقم: {0}." });
            TPaidSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مبيع لـ {0}, رقم: {1}." });

            //فاتورة بيع غير نقدية وبدون حسم
            TUnpaidSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مبيع آجلة, رقم: {0}." });
            TUnpaidSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مبيع آجلة لـ {0}, رقم: {1}." });

            //فاتورة بيع نقدية مع حسم
            TPaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة مبيع نقدية لـ {0}, رقم: {1}." });
            TPaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مبيع نقدية رقم: {0}." });
            TPaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مبيع نقدية رقم: {0}." });
            TPaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialGrantedDiscountAccount), Notes = "حسم على فاتورة مبيع لـ {0}, رقم {1}" });
            TPaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مبيع لـ {0}, رقم: {1}." });

            //فاتورة بيع غير نقدية مع حسم
            TUnpaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مبيع آجلة رقم: {0}." });
            TUnpaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialGrantedDiscountAccount), Notes = "حسم على فاتورة مبيع لـ {0}, رقم {1}" });
            TUnpaidSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مبيع لـ {0}, رقم: {1}." });
            #endregion

            #region فواتير الشراء بكافة أحوالها
            //فاتورة شراء نقدية بدون حسم
            TPaidBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة شراء نقدية رقم: {0}." }); //مدين
            TPaidBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة شراء نقدية لـ {0}, رقم: {1}." }); // دائن
            TPaidBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة شراء نقدية رقم: {0}." });  //دائن
            TPaidBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة شراء من {0}, رقم: {1}." });  //مدين

            //فاتورة شراء غير نقدية وبدون حسم
            TUnpaidBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة شراء آجلة, رقم: {0}." });  // دائن
            TUnpaidBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة شراء آجلة من {0}, رقم: {1}." });  //مدين

            //فاتورة شراء نقدية مع حسم
            TPaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة شراء نقدية رقم: {0}." });
            TPaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة شراء نقدية من {0}, رقم: {1}." });
            TPaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة شراء نقدية رقم: {0}." });
            TPaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialAcquiredDiscountAccount), Notes = "حسم على فاتورة شراء من {0}, رقم {1}" });
            TPaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة مبيع من {0}, رقم: {1}." });

            //فاتورة شراء غير نقدية مع حسم
            TUnpaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة شراء آجلة رقم: {0}." });
            TUnpaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialAcquiredDiscountAccount), Notes = "حسم على فاتورة شراء من {0}, رقم {1}" });
            TUnpaidBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة شراء من {0}, رقم: {1}." });
            #endregion

            #region فواتير مرتجع البيع بكافة أحوالها
            //فاتورة مرتجع بيع نقدية بدون حسم
            TPaidRSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مرتجع مبيع نقدية لـ {0}, رقم: {1}." }); //مدين
            TPaidRSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع نقدية لـ {0} رقم: {1}." }); //دائن
            TPaidRSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع نقدية لـ {0} رقم: {1}." }); //مدين
            TPaidRSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة مرتجع مبيع نقدية لـ {0}, رقم: {1}." }); //دائن

            //فاتورة مرتجع بيع غير نقدية وبدون حسم
            TUnpaidRSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مرتجع مبيع آجلة لـ {0}, رقم: {1}." });
            TUnpaidRSaleWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع آجلة, رقم: {0}." });

            //فاتورة مرتجع بيع نقدية مع حسم
            TPaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مرتجع مبيع نقدية لـ {0}, رقم: {1}." });
            TPaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialGrantedDiscountAccount), Notes = "حسم على فاتورة مرتجع مبيع لـ {0}, رقم {1}" });
            TPaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع نقدية رقم: {0}." });
            TPaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع نقدية رقم: {0}." });
            TPaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة مرتجع مبيع نقدية لـ {0}, رقم: {1}." });

            //فاتورة مرتجع بيع غير نقدية مع حسم
            TUnpaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مرتجع مبيع لـ {0}, رقم: {1}." });
            TUnpaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialGrantedDiscountAccount), Notes = "حسم على فاتورة مرتجع مبيع لـ {0}, رقم {1}" });
            TUnpaidRSaleWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع آجلة رقم: {0}." });
            #endregion

            #region فواتير مرتجع الشراء بكافة أحوالها
            //فاتورة مرتجع شراء نقدية بدون حسم
            TPaidRBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة مرتجع شراء نقدية لـ {0}, رقم: {1}." }); //دائن
            TPaidRBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع شراء نقدية رقم: {0}." }); //مدين
            TPaidRBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع شراء نقدية رقم: {0}." }); //دائن
            TPaidRBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة مرتجع شراء نقدية لـ {0}, رقم: {1}." }); //مدين

            //فاتورة مرتجع شراء غير نقدية وبدون حسم
            TUnpaidRBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع آجلة رقم: {0}." });
            TUnpaidRBuyWithoutDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة مرتجع شراء آجلة لـ {0}, رقم: {1}." });

            //فاتورة مرتجع شراء نقدية مع حسم
            TPaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع نقدية رقم: {0}." });
            TPaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialAcquiredDiscountAccount), Notes = "حسم على فاتورة مرتجع شراء لـ {0}, رقم {1}" });
            TPaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.PurchasesAccount), Notes = "فاتورة مرتجع شراء نقدية لـ {0}, رقم: {1}." });
            TPaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع نقدية رقم: {0}." });
            TPaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.FundAccount), Notes = "فاتورة مرتجع شراء نقدية لـ {0}, رقم: {1}." });

            //فاتورة مرتجع شراء غير نقدية مع حسم
            TUnpaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = null, Notes = "فاتورة مرتجع مبيع آجلة رقم: {0}." });
            TUnpaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.CommercialAcquiredDiscountAccount), Notes = "حسم على فاتورة مرتجع شراء لـ {0}, رقم {1}" });
            TUnpaidRBuyWithDiscount.Details.Add(new VoucherDetail { Account = accountObj.GetByNumber(Account.SalesAccount), Notes = "فاتورة مرتجع شراء لـ {0}, رقم: {1}." });
            #endregion

        }
        #endregion
    }
}
